﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VirtualOperator
{
  
   	public class GListBox : ListBox
	{
		private ImageList _myImageList = new ImageList();
		public ImageList ImageList
		{
			get {return _myImageList;}
			set {
					_myImageList = value;
 
					if(null!=_myImageList)
					{
						this.ItemHeight = _myImageList.ImageSize.Height;
					}
				}
		}
		public GListBox()
		{
			// Set owner draw mode
			this.DrawMode = DrawMode.OwnerDrawFixed;
			
		}
		protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
		{
			e.DrawBackground();
			e.DrawFocusRectangle();
			GListBoxItem item;
			Rectangle bounds = e.Bounds;
			Size imageSize = new Size(0,0);
		
			if(_myImageList!=null)
				imageSize = _myImageList.ImageSize;
 
			try
			{
				item = (GListBoxItem) Items[e.Index];
				if (item.ImageIndex != -1)
				{
					ImageList.Draw(e.Graphics, bounds.Left,bounds.Top,item.ImageIndex); 
 
					e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), 
						bounds.Left+imageSize.Width, bounds.Top+2);
				}
				else
				{
					e.Graphics.DrawString(item.Text, e.Font,new SolidBrush(e.ForeColor),
						bounds.Left, bounds.Top+2);
				}
			}
			catch
			{
			}
			base.OnDrawItem(e);
		}
	}//End of GListBox class

	// GListBoxItem class 
	public class GListBoxItem
	{
        private object _obj;
		private int _myImageIndex;
        private string _name = "";
		// properties 
        public object Object { get { return _obj; } }
		public string Text
		{
            get { return _obj.ToString().Replace("TabPage:", ""); }
		}
		public int ImageIndex
		{
			get {return _myImageIndex;}
			set {_myImageIndex = value;}
		}
		//constructor
		public GListBoxItem(object obj, int index)
		{
			_obj = obj;
			_myImageIndex = index;
		}
        public GListBoxItem(object obj, string name ,int index)
        {
            _obj = obj;
            _myImageIndex = index;
            _name = name;
        }
		public GListBoxItem(string text): this(text,-1){}
		public GListBoxItem(): this(""){}
		public override string ToString()
        {
            return _obj.ToString();
          
		}
	}//End of GListBoxItem class
       
   
}
